package com.estar.integaration.Util;

import com.estar.integaration.entity.Material;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Author: YJL
 * Date: 2021/11/24 20:34
 **/
public class StreamUtil {

  /**
   * 需购大于0
   * @param materialList
   * @return
   */
  public static List<Material> filterListUnpurchasedBiggerThanZero(List<Material> materialList){
    List<Material> sortedPurL = materialList.stream()
        .filter(x ->
            {
              if(x.getUnpurchased() == null)
                return false;
              return x.getUnpurchased() > 0;
            }

        )
        .sorted(Comparator.comparing(Material::getMaterialNo))
        .collect(Collectors.toList());
    return sortedPurL;
  }

  /**
   * 库存大于0
   */
  public static List<Material> filterListInventoryBiggerThanZero(List<Material> materialList){
    List<Material> sortedPurL = materialList.stream()
            .filter(
                x -> {
                  if(x.getInventory() == null){
                    return false;
                  }
                  return x.getInventory() > 0;
                }

            )
            .sorted(Comparator.comparing(Material::getMaterialNo))
            .collect(Collectors.toList());
    return sortedPurL;
  }
  /**
   * 需购为0
   * @param materialList
   * @return
   */
  public static List<Material> filterListUnpurchasedEQZero(List<Material> materialList){
    List<Material> sortedPurL = materialList.stream()
        .filter(x ->{
          if(x.getUnpurchased() == null)
            return false;
          return x.getUnpurchased() == 0;
        }  )
        .sorted(Comparator.comparing(Material::getMaterialNo))
        .collect(Collectors.toList());
    return sortedPurL;
  }

}
